/**
 * 
 */
package database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.ArrayList;

import database.RequestParser;

import forum.Forum;
import forum.Member;
import forum.Post;
import forum.Thread;

/**
 * @author Alon Segal
 *
 */
public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		Connection conn = null;
		try {
			System.out.println("Starting DB test");
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager
							//.getConnection("jdbc:mysql://132.72.198.240:3306/forum","root","2598");
							.getConnection("jdbc:mysql://localhost:3306/forum","root","2598");

			RequestParser rp = new RequestParser(conn);
			//Test.testGetFriends(rp);
			//Test.testAddFriend(rp);
			//Test.testGetFriends(rp);
			//Test.testRemoveFriend(rp);
			//Test.testGetFriends(rp);
			//Test.testRegisterUser(rp);
			//Test.testRemoveUser(rp);
			//Test.testLogin(rp);
			//Test.testIsModerator(rp);
			//Test.testAddForum(rp);
			//Test.testGetForums(rp);
			//Test.testRemoveForum(rp);
			//Test.testGetThreads(rp);
			//Test.testAddThread(rp);
			//Test.testGetThreads(rp);
			//Test.testRemoveThread(rp);
			//Test.testAddReply(rp);
			//Test.testRemoveReply(rp);
			//Test.testGetThread(rp);
			//Test.testGetPost(rp);
			//Test.testEditPost(rp);
			//Test.testGetThreadsIds(rp);
			//Test.testGetInfoAboutFriend(rp);
			
			
		} catch (Exception e) {
			System.out.println(e);
			System.exit(0);
		}
		
	}
	
	private static void testGetInfoAboutFriend(RequestParser rp) {
		
		Member m = rp.parseGetInfoAboutFriend("alonseg");
			System.out.println(m.getUsername());
	}
	
	private static void testGetThreadsIds(RequestParser rp) {
		
		ArrayList<Integer> f = rp.parseGetThreadsIds();
		for(int i=0; i<f.size(); i++) {
			System.out.println(f.get(i));
		}
	}
	
	private static void testEditPost(RequestParser rp) {
		
		System.out.println(rp.parseEditPost(1, "wow new content"));
	}
	
	private static void testGetPost(RequestParser rp) {
		Post p = rp.parseGetPost(1);
		System.out.println(p.getID()+" "+p.getSubject()+" "+
				p.getContent()+" "+p.getDate()+" "+ 
				p.getAuthor());
	}
	
	private static void testGetThread(RequestParser rp) {
		
		ArrayList<Post> t = rp.parseGetThread(1);
		for(int i=0; i<t.size(); i++) {
			System.out.println(t.get(i).getID()+" "+t.get(i).getSubject()+" "+
					t.get(i).getContent()+" "+t.get(i).getDate()+" "+ 
					t.get(i).getAuthor());
		}
	}
	
	private static void testRemoveReply(RequestParser rp) {
		
		System.out.println(rp.parseRemoveReply(4));
	}
	
	private static void testAddReply(RequestParser rp) {
		
		System.out.println(rp.parseAddReply(10, "navea", "some reply", "reply content", "24/02/1980"));
	}
	
	private static void testRemoveThread(RequestParser rp) {
		
		System.out.println(rp.parseRemoveThread(7));
	}
	
	private static void testAddThread(RequestParser rp) {
		
		System.out.println(rp.parseAddThread("alonseg", 2, "new sub", "yada yada", "14/05/2011"));
	}
	
	private static void testGetThreads(RequestParser rp) {
		
		ArrayList<Thread> f = rp.parseGetThreads(2);
		for(int i=0; i<f.size(); i++) {
			System.out.println(f.get(i).getID()+" "+f.get(i).getRoot().getSubject()+" "+
					f.get(i).getRoot().getContent()+" "+ f.get(i).getRoot().getAuthor());
		}
	}
	
	private static void testRemoveForum(RequestParser rp) {
		
		System.out.println(rp.parseRemoveForum(4));
	}
	
	private static void testAddForum(RequestParser rp) {
		
		System.out.println(rp.parseAddForum("forum4"));
	}
	
	private static void testGetForums(RequestParser rp) {
		
		ArrayList<Forum> f = rp.parseGetForums();
		for(int i=0; i<f.size(); i++) {
			System.out.println(f.get(i).getID()+" "+f.get(i).getSubject());
		}
	}
	
	private static void testIsModerator(RequestParser rp) {
		
		System.out.println(rp.parseIsModerator("alonseg"));
	}
	
	private static void testLogin(RequestParser rp) {
		
		System.out.println(rp.parseLogin("alon26", "123"));
	}

	private static void testAddFriend(RequestParser rp) {
		
		System.out.println(rp.parseAddFriend("alonseg", "olgasib"));
	}
	
	private static void testRemoveFriend(RequestParser rp) {
		
		System.out.println(rp.parseRemoveFriend("alonseg", "olgasib"));
	}
	
	private static void testRegisterUser(RequestParser rp) {
		
		System.out.println(rp.parseRegisterUser("alon26", "alon", "segal2", "123", "alon26@gmail.com","m"));
	}
	
	private static void testRemoveUser(RequestParser rp) {
		
		System.out.println(rp.parseRemoveUser("alon26"));
	}

	private static void testGetFriends(RequestParser rp) {
		ArrayList<Member> m = rp.parseGetFriends("alonseg");
		for(int i=0; i<m.size(); i++) {
			System.out.println(m.get(i).getUsername());
		}
	}
}
